package com.example.gamestore.control;

import com.example.gamestore.Bean.Cart;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class CartControl {
    @GetMapping("/deleteitem")
    @ResponseBody
    public String deleteitem(Integer id, HttpSession session){
        Cart cart =(Cart) session.getAttribute("cart");
        if(cart!=null){
            cart.deleteItem(id);
            return "成功";
        }
        return "失败";
    }
    @GetMapping("updatecount")
    @ResponseBody
    public String updatecount(Integer id,Integer count,HttpSession session){
        Cart cart =(Cart) session.getAttribute("cart");
        if(cart!=null){
            cart.updateCount(id,count);
            return "修改成功";
        }
        return "修改失败";
    }
    @GetMapping("clearall")
    @ResponseBody
    public String clearall(HttpSession session){
        Cart cart =(Cart) session.getAttribute("cart");
        if(cart!=null){
            cart.clear();
            return "清空成功";
        }
        return "清空失败";
    }
}
